﻿<%@ WebHandler Language="C#" Class="LoadGridHandler" %>

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using Business.Common;
using Business.Map;

public class LoadGridHandler : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        var pageSize = Convert.ToInt32(context.Request["rows"]);
        var pageNum = Convert.ToInt32(context.Request["page"]);
        context.Response.ContentType = "text/plain";
        context.Response.Write(GetDataJsonStr(pageSize, pageNum));
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
    private static string GetDataJsonStr(int pageSize, int pageNum)
    {
        var dtEstateHouse = MapBLL.GetEstateHouse();
        var list = new List<EstateHouse>();
        dtEstateHouse.Rows.Cast<DataRow>().ToList().ForEach(row => list.Add(new EstateHouse
        {
            ID = row["id"].ToString(),
            IID = row["iid"].ToString(),
            InputIndex = row["input_index"].ToString(),
            BelongProject = row["ssxm"].ToString(),
            PayTime = row["zfsj"].ToString(),
        }));
        var result = new EasyuiModel<EstateHouse>
        {
            Total = dtEstateHouse.Rows.Count,
            Rows = list.Skip((pageNum - 1) * pageSize).Take(pageSize).ToList()
        };
        return result.T2Json();
    }
}